package com.lqq.sparrow.proxy;

import com.lqq.sparrow.util.ProxyUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liangqq
 */
public abstract class ProxyFactory{

    /**
     * 获取所有的远程服务代理对象
     * @return
     */
    public List<ProxyInstance> getAllRemoteService(){
        //TODO
        List<Class> interfaceClassList = getAllRemoteClass();
        return getAllRemoteService(interfaceClassList);
    }

    public List<ProxyInstance> getAllRemoteService(List<Class> interfaceClassList){
        List<ProxyInstance> proxyInstanceList = new ArrayList<ProxyInstance>(interfaceClassList.size());
        for(Class clazz: interfaceClassList){
            ProxyInstance proxyInstance = new ProxyInstance();
            String name = clazz.getSimpleName();
            Object instance = ProxyUtil.getBean(clazz);
            proxyInstance.setName(name);
            proxyInstance.setInstance(instance);
            proxyInstanceList.add(proxyInstance);
        }
        return proxyInstanceList;
    }

    /**
     * 获取远程服务的class,扫描工作交给子类实现
     * @return
     */
    public abstract List<Class> getAllRemoteClass();

}
